#include<bits/stdc++.h>

using namespace std;

int SearchMedian(int A[], int B[], int n) {
    int left1 = 0, right1 = n - 1;
    int left2 = 0, right2 = n - 1;
    while (left1 + 1 < right1 || left2 + 1 < right2) {
        int mid1 = (left1 + right1) >> 1;
        int mid2 = (left2 + right2) >> 1;
        if (A[mid1] == B[mid2])
            return A[mid1];
        if (A[mid1] > B[mid2]) {
            right1 = mid1;
            left2 = mid2;
        } else {
            left1 = mid1;
            right2 = mid2;
        }
    }
    if (A[left1] > B[left2]) {
        return min(A[left1], B[right2]);
    } else {
        return min(A[right1], B[left2]);
    }
}

int main() {
    //  测试
    int n = 5;
    int A[] = {11, 13, 15, 17, 19};
    int B[] = {2, 4, 6, 8, 20};
    cout << SearchMedian(A, B, n) << endl;
    return 0;
}